import requests
import json
from helpme.settings import BUYER_CONTENT_TEMP, SUPPLIER_CONTENT_TEMP
LOCAL = 'http://localhost:8000'


def add_user(phone, passwd):
    url = LOCAL + "/suppliers/"
    data = {
        'phone': phone,
        'password': passwd
    }
    res = requests.post(url, data=data)

    print(res.headers)
    print(res.json())

def add_order():
    url = LOCAL + "/orders/"
    res = requests.post(
        url,
        {
            'buyer_id': '1',
            'content': json.dumps(BUYER_CONTENT_TEMP),
            'items': json.dumps([{'id': 1, 'count': 10}])
        }
    )
    print(res.json())


def add_goodItem():
    url = LOCAL + "/goods/"
    res = requests.post(
        url,
        {
            'buyer_id': '1',
            'content': json.dumps(BUYER_CONTENT_TEMP),
            'items': json.dumps([{'id': 1, 'count': 10}])
        }
    )
    print(res.json())

def upload():
    url = LOCAL + "/goods/upload_img/"
    res = requests.post(
        url,
        {
            'good_id': 1,
        },
        files={'img': ('test.jpg', open('/home/louis/Desktop/1.png', 'rb'), 'image/png')}
    )
    print(res.json())
if __name__ == '__main__':
    # add_user('13554446', '123aqqs')
    # add_order()
    upload()